let api = require('../../../api/index');
let http =require('../../../utils/http')
Page({
    data: {
        list: [],
        form: {
            page: 1,
            pagesize: 10,
        },
        pageStatus: 1 // 1下拉加载更多..  5加载中... 10没有更多了... 99暂无数据
    },
    onLoad: function (options) {
        this.reload()
    },
    onShow: function () {

    },
    onPullDownRefresh: function () {
    
    },
    onReachBottom: function () {
        this.setData({
            "form.page":this.data.form.page+1,
            "form. pagesize":this.data.pagesize+10
        })
        this.getLIST()
    },
    reload() {
        console.log('初次加载')
        // this.getList('reset')
        this.getLIST()
    },
    getLIST(){
        let that=this
        let obj={
            page: this.data.form.page,
            pagesize: this.data.form.pagesize,
            type: this.data.active
        }
        http.request("GET",'/bargain/my_bargain',obj).then((res)=>{
            
                that.setData({
                    list:res.data.ResData.Items
                })
                console.log(that.data.list,"我的砍价");
            
        })
    },
    getList(type) {
        if (type === 'reset') {
            this.setData({
                ['form.page']: 1,
                // list: [],
                pageStatus: 1
            })
        }


        if (this.data.pageStatus !== 1) {
            return false
        } else {
            this.setData({
                pageStatus: 5
            })
        }

        api.bargain.getBargainList({
            page: this.data.form.page,
            pagesize: this.data.form.pagesize,
            type: this.data.active
        }).then(res => {
            let list = res.data.ResData.Items
            let pageSize = res.data.ResData.ItemsPerPage
            let pageStatus;

            if (this.data.list.pageNum > 1) {
                list = this.data.list.concat(list);
            }

            if (list.length < pageSize) {
                if (list.length <= 0) {
                    pageStatus = 99
                } else {
                    pageStatus = 10
                }
            } else {
                pageStatus = 1
            }

            this.setData({
                list: list,
                pageStatus: pageStatus,
                ['form.page']: this.data.form.page++,
            })
        })
    },
    toPagesDetails(e) {
        let info = e.currentTarget.dataset.item;
        console.log(info);
        wx.navigateTo({
            url: `/component/KJdetles/KJdtels?id=${info.id}&spec_id=${info.spec_id}&title=${info.goodsDto.Title}&money=${info.current_amount}&img=${info.goodsDto.GoodsFileDtos[0].FilePath}&endtime=${info.end_time}&bargain_id=${info.bargain_id}&SpecName=${info.goodsDto.SpecName}&Price=${info.goodsDto.Price}&goods_id=${info.goods_id}&bargain_id=${info.bargain_id}&order_id=${info.order_id}`,
        })
    }
})